package com.gintama.service.impl;

import com.gintama.service.AsycService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class AsycServiceImpl implements AsycService {

    @Override
    @Async  // 在异步配置类设置了默认线程池则不需要再指定线程池名称
    public void doTask1() {
        long t1 = System.currentTimeMillis();
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        long t2 = System.currentTimeMillis();
        System.out.println("任务1执行时间：" + (t2 - t1));
    }

    @Override
    @Async
    public void doTask2() {
        long t1 = System.currentTimeMillis();
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        long t2 = System.currentTimeMillis();
        System.out.println("任务1执行时间：" + (t2 - t1));
    }
}
